﻿Imports System.Linq
Imports TNCDAL

Public Class AdvanceDriverController
    Private objRepository As New AdvanceDriverRepository

    Public Function SelectAllRecord() As IQueryable(Of tblAdvanceDriver)
        Return objRepository.SelectAllRecord()
    End Function

    Public Function SelectRecordById(ByVal id As Integer) As tblAdvanceDriver
        Return objRepository.SelectRecordById(id)
    End Function

    Public Sub Insert(ByVal obj As tblAdvanceDriver)
        objRepository.Insert(obj)
    End Sub

    Public Sub Update(ByVal obj As tblAdvanceDriver)
        objRepository.Update(obj)
    End Sub

    Public Sub Delete(ByVal obj As tblAdvanceDriver)
        objRepository.Delete(obj)
    End Sub

    Public Function SelectAllRecord_Custom(ByVal month As Integer, ByVal id_Driver As Integer, ByRef total As Double) As IQueryable
        Dim query = From p In objRepository.SelectAllRecord()
               Where p.AdvanceDate.Value.Month = month And p.ID_Driver = id_Driver
               Select p.ID_AdvanceDriver, p.AdvanceDate, p.tblDriver.DriverName, p.Amount

        Try
            total = (From p In query
                    Select p.Amount).Sum()
        Catch ex As Exception
            total = 0
        End Try
        

        Return query
    End Function
    
End Class

